Skip to content

Add recurring job to notify group admins of bounces#2088

Merged
stephencdaly merged 6 commits into
mainfrom
add-recurring-job-to-notify-group-admins-of-bounces
May 13, 2026
Merged

Add recurring job to notify group admins of bounces#2088
stephencdaly merged 6 commits into
mainfrom
add-recurring-job-to-notify-group-admins-of-bounces

Conversation

@stephencdaly
Copy link
Copy Markdown
Contributor

@stephencdaly stephencdaly commented May 11, 2026

What problem does this pull request solve?

Trello card: https://trello.com/c/CsEqMtDL

Adds 2 jobs:

  • SendBounceNotificationsJob to find all forms with bounces on a given date and send emails to the group admins using Notify
  • ScheduleBounceNotificationsJob to be run by the scheduler on a daily recurring schedule. This job just exists so that the SendBounceNotificationsJob can accept a date to make it possible to retry it for the same date if it fails.

We only want to turn this on when we're notifying Organisation Admins after a week has passed if deliveries are still marked as bounced. Instead of adding a feature flag, I thought it was easier to just not add the recurring schedule to recurring.yml until notifying org admins is ready.

Testing

This is a little tricky to test, but can be tested locally by:

  1. Creating a submission
  2. Updating the delivery for the submission to be bounced by setting failed_at (to yesterday), failure_reason, failure_details. The failure_details should be { "bounceType" => "Permanent" } for a hard bounce and { "bounceType" => "Transient" } for a soft bounce.
  3. Updating recurring.yml to schedule the schedule_bounce_notifications_job recurring task to be on a schedule that will run soon (e.g. every minute or a set time in the future).
  4. Run Solid Queue locally following the instructions in the README to update development.rb and running ./bin/jobs with: SETTINGS__GOVUK_NOTIFY__API_KEY=your-test-notify-key PGGSSENCMODE="disable" ASSUME_DEV_IAM_ROLE=true ./bin/jobs

I've tested that it works by pushing the branch to dev, and with different types of bounces by testing locally, so if you're satisfied by my testing you don't need to test again.

Email for a hard bounce (tested on dev):

Screenshot 2026-05-11 at 12 57 34

Email for a soft bounce (tested locally). The deadline date is a bit odd for this one, but that's just because I messed around with dates of delivery records in the rails console, and locally we delete submissions after 5 minutes:

Screenshot 2026-05-11 at 12 58 21

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Do the end to end tests need updating before these changes will pass?
  • Has all relevant documentation been updated?

@stephencdaly stephencdaly force-pushed the add-recurring-job-to-notify-group-admins-of-bounces branch 6 times, most recently from b91abbd to c40e2a3 Compare May 11, 2026 14:31
@stephencdaly stephencdaly marked this pull request as ready for review May 12, 2026 08:49
@stephencdaly stephencdaly force-pushed the add-recurring-job-to-notify-group-admins-of-bounces branch 2 times, most recently from b0e5539 to 910c3f7 Compare May 12, 2026 11:33
This makes a request to /api/v2/forms/:form_id/group to get the group
for a form. The group response includes the group name, names and
email addresses of the group admins and the organisation details -
name and details of organisation admins.

Also add factories for a group and and an admin user included in the
groups API response.
Add mailer with a method to send bounce notification emails to
group admins using Notify.
Add a job to find all forms that have deliveries that bounced on the
given date and send notification emails to the group admins for those
forms.

This accepts a date as a parameter so that the job can be retried if
it fails and still send notifications for the given date. This will be
scheduled by another job run on a daily schedule.
We want the job that sends bounce notifications to run on a schedule
every day, and we want it to be retryable if it fails. Add a job that
will run on a schdedule to enqueue the SendBounceNotificationsJob to
send bounce notifications for the previous day so that retrying the
job will send bounces for that day.
We'll add the schedule on production environments when we've also
added sending notifications to Organisation Admins after a week if
the delivery is still marked as bounced.
@stephencdaly stephencdaly force-pushed the add-recurring-job-to-notify-group-admins-of-bounces branch from 910c3f7 to c68818e Compare May 13, 2026 12:52
@github-actions
Copy link
Copy Markdown
Contributor

🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2088.submit.review.forms.service.gov.uk/

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

@stephencdaly stephencdaly added this pull request to the merge queue May 13, 2026
Merged via the queue into main with commit fd6531f May 13, 2026
3 checks passed
@stephencdaly stephencdaly deleted the add-recurring-job-to-notify-group-admins-of-bounces branch May 13, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants